import parkService from "../service/park";
import { codeFail, codeSuccess } from "./resultData";
import {queryNotice} from "../dao/tree";

const BASE_URL = '/apple/park'
export default function (app: any) {
    app.get(BASE_URL + "/list", async (req, res) => {
        const data = await parkService.queryList();
        res.send(codeSuccess(data));
    });
    app.get(BASE_URL, async (req, res) => {
        const data = await parkService.queryById(req.query.id);
        res.send(codeSuccess(data[0]));
    });
    app.post(BASE_URL, async (req, res) => {
        console.log(req.body.data);
        const data = await parkService.insert(req.body.data);
        if (!data) {
            return res.send(codeFail("新增失败"));
        }
        res.send(codeSuccess(data));
    });
    app.delete(BASE_URL, async (req, res) => {
        const data = await parkService.deleteById(req.query.id);
        if (!data) {
            return res.send(codeFail("删除失败"));
        }
        res.send(codeSuccess());
    });
    app.put(BASE_URL, async (req, res) => {
        res.send(await parkService.update(req.body.data));
    });

    app.get(BASE_URL + "/notice", async (req, res) => {
        const data = await parkService.queryNotice();
        return res.send(codeSuccess(data));
    });
    app.get(BASE_URL + "/chart/cost", async (req, res) => {
        const data = await parkService.queryCost();
        return res.send(codeSuccess(data));
    });
    app.get(BASE_URL + "/chart", async (req, res) => {
        const data = await parkService.queryChart();
        return res.send(codeSuccess(data));
    });
}
